/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * clave.java
 *
 * Created on 07/01/2009, 11:21:08 PM
 */
package UIDelNegocio;

import LogicaDeNegocio.Empleado;
import LogicaDeNegocio.Main;
import javax.swing.JOptionPane;

/**
 *
 * @author Anya
 */
public class clave extends javax.swing.JFrame {

    public static int opc;

    /** Creates new form clave */
    public clave(int opc1) {
        opc = opc1;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("WellDressing");

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel1.setText("Nombre de Usuario");

        jLabel2.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel2.setText("Contraseña");

        jTextField1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N

        jPasswordField1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N

        jButton1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jButton1.setText("Aceptar");
        jButton1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextField1)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE))
                .addContainerGap(60, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(276, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(66, 66, 66))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int gerente = 2;
        int administrador = 1;
        Main control = new Main();
        if (jTextField1.getText().compareTo("") == 0 || jPasswordField1.getText().compareTo("")== 0) {
            JOptionPane.showMessageDialog(this, "Debe llenar los campos Nombre y Contraseña", "WellDressing", JOptionPane.ERROR_MESSAGE);
        } else {
            if (opc == 1) {
                Empleado login = (Empleado) control.consultarEmpleado(Integer.parseInt(jPasswordField1.getText()));
                if (jTextField1.getText().equals(login.getNombre()) && login.getCargo().equals("Administrador")) {
                    Adminis vent = new Adminis(jTextField1.getText().toString(), "");
                    vent.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(this, "El nombre y/o la clave son incorrectos", "WellDressing", JOptionPane.ERROR_MESSAGE);
                }

            } else {
                Empleado login = (Empleado) control.consultarEmpleado(Integer.parseInt(jPasswordField1.getText()));
                //System.out.println("GERENTE");
                System.out.println(login.getNombre());
                if (jTextField1.getText().equals(login.getNombre()) && login.getCargo().equals("Gerente")) {
                    Gerente vent = new Gerente();
                    vent.setVisible(true);
                }
            }
        }
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed
    /**
     * @param args the command line arguments
     */
    /*public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new clave().setVisible(true);
    }
    });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
